package com.cookbook.cookbookservice.common.base;

import cn.hutool.core.util.ObjectUtil;
import lombok.Data;

/**
 * @program: mid-tourism-service
 * @ClassName BaseResponse
 * @description:
 * @author: MiaoChao
 * @create: 2024-02-23 14:50
 * @Version 1.0
 **/
@Data
public class BaseResponse<T> {

    private Boolean success;

    private Object message;

    private T data;

    private Integer code;

    public BaseResponse(Boolean success, Object message, T data, Integer code) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.success = success;
    }


    public static BaseResponse success(Object data) {
        return new BaseResponse(true, "success", data, 200);
    }

    public static BaseResponse fail(Object data) {
        return new BaseResponse(false, "fail", data, 4000);
    }

    public static BaseResponse fail(Integer code, Object data) {
        return new BaseResponse(false, data, null, ObjectUtil.isNotEmpty(code) ? code : 5000);
    }

}